package net.pimpas.core.configuration.file;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URL;

import net.pimpas.util.EqualsHelper;

import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 
 * @author pc
 *
 */
public class DefaultFileConfiguration implements FileConfiguration {

	private InputStream inputStream;
	private URL fileUrl;
	
	public DefaultFileConfiguration(URL file, InputStream input) {
		this.setFileUrl(file);
		this.setInputStream(input);
	}
	
	public InputStream openInputStream() throws FileNotFoundException {
		return this.getInputStream();
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

	public URL getFileUrl() {
		return fileUrl;
	}

	private void setFileUrl(URL fileUrl) {
		this.fileUrl = fileUrl;
	}
	
	@Override
	public int hashCode() {
		return new HashCodeBuilder()
			.append(this.getFileUrl()).toHashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		return EqualsHelper.equals(this, obj, "fileUrl");
	}
}